import 'dart:math';

import 'package:backend.core/core/domain/entities/email_verification_code.dart';

abstract class IssueEmailVerificationCode {
  EmailVerificationCode call({
    required String email,
  });
}

class IssueEmailVerificationCodeImpl implements IssueEmailVerificationCode {
  const IssueEmailVerificationCodeImpl();

  @override
  EmailVerificationCode call({
    required String email,
  }) {
    final value = (Random().nextInt(9000) + 1000).toString();
    final currentTime = DateTime.now().toUtc();
    final expirationTime = currentTime.add(const Duration(minutes: 5));

    return EmailVerificationCode(
      value: value,
      expirationTime: expirationTime,
      email: email,
      remainingAttempts: 3,
    );
  }
}
